<template>
  <div class="delivery">
    <!-- <header class="page-header">
      <h1>订单</h1>
    </header> -->
    <main class="orders-content">
      <div v-if="cartStore.items.length === 0" class="empty-cart">
        <p>购物车是空的</p>
        <button class="go-shopping-btn" @click="router.push('/order')">去购买</button>
      </div>
      <div v-else class="cart-items">
        <div class="cart-item" v-for="item in cartStore.items" :key="item.id">
          <div class="item-info">
            <div class="item-image placeholder" v-if="item.image">
              <img :src="`http://localhost:3005/${item.image}`" :alt="item.title">
            </div>
            <div class="item-details">
              <h3>{{ item.title }}</h3>
              <p class="item-price">¥{{ Number(item.price).toFixed(1) }}</p>
            </div>
          </div>
          <div class="item-quantity">
            <button class="quantity-btn" @click="cartStore.updateQuantity(item.id, item.quantity - 1)">-</button>
            <span>{{ item.quantity }}</span>
            <button class="quantity-btn" @click="cartStore.updateQuantity(item.id, item.quantity + 1)">+</button>
          </div>
          <button class="remove-btn" @click="cartStore.removeFromCart(item.id)">删除</button>
        </div>
        <div class="cart-summary">
          <div class="total-amount">总计: ¥{{ cartStore.totalAmount.toFixed(1) }}</div>
          <button class="checkout-btn" @click="submitOrder">结算</button>
        </div>
      </div>
    </main>
  </div>
</template>

<script setup lang="ts">
import { useCartStore } from '../stores/cart'
import { useRouter } from 'vue-router'

const cartStore = useCartStore()
const router = useRouter()
const submitOrder = () => {
  // 提交订单逻辑
  console.log('提交订单')
  router.push('/shopping/settlement')
}
</script>

<style scoped>
.delivery {
  padding: 20px;
  padding-bottom: 76px;
  animation: fadeIn 0.3s ease-in-out;
  background-color: #f8f5f2;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.page-header {
  margin-bottom: 24px;
  text-align: center;
}

.page-header h1 {
  font-size: 28px;
  color: #4a3728;
  margin: 0;
  font-weight: 600;
  letter-spacing: 1px;
}

.orders-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.order-item {
  background: #fff;
  border-radius: 12px;
  padding: 15px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.order-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.order-number {
  color: #666;
  font-size: 14px;
}

.order-status {
  color: #42b883;
  font-size: 14px;
}

.order-details {
  border-bottom: 1px solid #eee;
  padding-bottom: 12px;
  margin-bottom: 12px;
}

.restaurant-info h3 {
  margin: 0;
  font-size: 16px;
  color: #333;
}

.order-time {
  color: #999;
  font-size: 14px;
  margin: 4px 0;
}

.order-items {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.items-summary {
  color: #666;
  font-size: 14px;
  margin: 0;
}

.order-price {
  color: #f56c6c;
  font-size: 16px;
  font-weight: bold;
}

.order-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.action-btn {
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid #ddd;
  background: #fff;
  color: #666;
  transition: all 0.2s;
}

.action-btn.primary {
  background: #42b883;
  color: white;
  border-color: #42b883;
}

.action-btn:hover {
  opacity: 0.8;
}

.cart-items {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-left: -50px;
  width: 500px;
}

.cart-item {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 12px rgba(74, 55, 40, 0.08);
  transition: transform 0.2s ease;
}

.cart-item:hover {
  transform: translateY(-2px);
}

.item-info {
  flex: 1;
  display: flex;
  align-items: center;
  min-width: 0;
}

.item-image {
  flex: 0 0 100px;
  width: 100px;
  height: 100px;
  border-radius: 12px;
  overflow: hidden;
  margin-right: 20px;
  box-shadow: 0 4px 8px rgba(74, 55, 40, 0.1);
}

.item-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.item-info h3 {
  margin: 0;
  font-size: 18px;
  color: #4a3728;
  font-weight: 500;
}

.item-price {
  color: #8b5e3c;
  font-size: 18px;
  margin: 4px 0 0;
  font-weight: 600;
}

.item-quantity {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 24px;
  background: #f8f5f2;
  padding: 8px 16px;
  border-radius: 20px;
}

.quantity-btn {
  width: 28px;
  height: 28px;
  border-radius: 14px;
  border: none;
  background: #fff;
  color: #4a3728;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(74, 55, 40, 0.1);
}

.quantity-btn:hover {
  background: #4a3728;
  color: #fff;
}

.remove-btn {
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid #8b5e3c;
  background: transparent;
  color: #8b5e3c;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
}

.remove-btn:hover {
  background: #8b5e3c;
  color: #fff;
}

.cart-summary {
  margin-top: 24px;
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 12px rgba(74, 55, 40, 0.08);
}

.total-amount {
  font-size: 20px;
  font-weight: 600;
  color: #4a3728;
}

.checkout-btn {
  padding: 12px 32px;
  border-radius: 24px;
  background: #8b5e3c;
  color: white;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
  font-size: 16px;
  letter-spacing: 0.5px;
}

.checkout-btn:hover {
  background: #4a3728;
  transform: translateY(-2px);
}

.empty-cart {
  text-align: center;
  padding: 60px 20px;
  color: #8b5e3c;
  font-size: 18px;
}

.go-shopping-btn {
  margin-top: 20px;
  padding: 12px 32px;
  border-radius: 24px;
  background: #8b5e3c;
  color: white;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
  font-size: 16px;
  letter-spacing: 0.5px;
}

.go-shopping-btn:hover {
  background: #4a3728;
  transform: translateY(-2px);
}

.item-image {
  width: 100px;
  height: 100px;
  border-radius: 12px;
  overflow: hidden;
  margin-right: 20px;
  box-shadow: 0 4px 8px rgba(74, 55, 40, 0.1);
}

.item-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.item-image img:hover {
  transform: scale(1.05);
}
</style>